package com.ywqf_api.controller;


import com.sun.org.apache.bcel.internal.generic.RETURN;
import com.ywqf_api.dto.exc.ClientExcution;
import com.ywqf_api.dto.exc.ReturnExcution;
import com.ywqf_api.dto.in.GoodsDecorationDto;
import com.ywqf_api.dto.in.GoodsInfoDto;
import com.ywqf_api.entity.Goods;
import com.ywqf_api.entity.GoodsList;
import com.ywqf_api.enums.ClientEnum;
import com.ywqf_api.enums.ReturnEnum;
import com.ywqf_api.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;
    @RequestMapping(value = "/getCleanInfo" ,method = RequestMethod.GET)
    @ResponseBody
    public ReturnExcution getCleanInfo(Integer goodsId){

        Goods good = goodsService.findGoodsInfo(goodsId);
        if (good == null){
//            return new ReturnExcution(ReturnEnum.FIND_FILE);
        }
        return new ReturnExcution(ReturnEnum.FIND_SUCCESS,good);

    }

    /**
     * 商品房
     * @param
     * @return
     */
    @RequestMapping(value = "/findCommunity" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findCommunity(int goodsId){
        Map findCommunity=goodsService.findCommunity(goodsId);
        return new ClientExcution(ClientEnum.SUCCESS,findCommunity);
    }

    @RequestMapping(value = "/addCommunity" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution addCommunity(GoodsInfoDto goodsInfoDto){

        int addCommunity=goodsService.addCommunity(goodsInfoDto);
        if (addCommunity>0){
            return new ClientExcution(ClientEnum.INSERT_SUCCESS,addCommunity);
        }
        return new ClientExcution(ClientEnum.INSERT_ERROR,null);
    }
    @RequestMapping(value = "/findDecoration" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findDecoration(int goodsId){
        Map findDecoration=goodsService.findDecoration(goodsId);
        return new ClientExcution(ClientEnum.SUCCESS,findDecoration);
    }


    @RequestMapping(value = "/addDecoration" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution addDecoration(GoodsDecorationDto goodsDecorationDto){
        int addDecoration=goodsService.addDecoration(goodsDecorationDto);
        return new ClientExcution(ClientEnum.INSERT_SUCCESS,addDecoration);
    }

    @RequestMapping(value = "/findIsReservation" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findIsReservation(Integer customerId,Integer goodsId){
        int hasAppointment=goodsService.findIsReservation(customerId,goodsId);
        return new ClientExcution(ClientEnum.SUCCESS,hasAppointment);
    }
    @RequestMapping(value = "/findGoodsList" ,method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findGoodsList(int customerId ,int type){
        List<GoodsList> findGoodsList= goodsService.findGoodsList(customerId, type);
        if (findGoodsList == null){
            return new ClientExcution(ClientEnum.NO_DATA,null);
        }
        return new ClientExcution(ClientEnum.SUCCESS,findGoodsList);
    }
}

